<?php
namespace app\servergoods\service\goods;

use \app\manage\service\ApiBase;

/**
 * @author:      李颖
 * @DateTime:    2017-07-06 09:35:54
 * @Description: 商品分类
 */
class GoodsCategory extends ApiBase
{
    protected $goodsCategoryLogic = '\app\servergoods\logic\GoodsCategory';
    protected $goodsCategoryValidate = '\app\servergoods\validate\GoodsCategory';

    use \app\serveruser\traits\AddAppIdToRunOne;

    //获取商品分类列表
    public function goodsCateList(): array
    {
        $data = $this->issetReceiveData(['id'=>0,'token'=>' ']);
        return $this->stepRun($data, 'servergoods/goods/GoodsCategory/goodsCateList', 'goodsCateList', 'goodsCateList');
    }

    //亚艺后台获取某商品分类信息
    public function oneCateInfo(): array 
    {
        $data = $this->haveIssetReceiveData(['id'=>0, 'token'=>' ']);
        return $this->stepRun($data, 'servergoods/goods/GoodsCategory/oneCateInfo', 'oneCateInfo', 'oneCateInfo');
    }

    //为某个应用添加商品分类
    public function addGoodsCate(): array 
    {
        $data = $this->haveIssetReceiveData(['app_id'=>'','other_app_read'=>'','is_public'=>0,'name'=>' ','cate_attrs'=>[],'pid'=>0,'profile_pic'=>'','keywords'=>'','description'=>'','order'=>100]);
        return $this->oneStepRun($data, 'servergoods/goods/GoodsCategory/addGoodsCate', 'addGoodsCate');
    }

    /*编辑商品分类*/
    public function editGoodsCate(): array 
    {
        $data = $this->issetReceiveData(['token'=>' ','other_app_read'=>'','is_public'=>0,'name'=>' ','cate_attrs'=>[],'id'=>0,'profile_pic'=>'','keywords'=>'','description'=>'','order'=>100]);
        return $this->stepRun($data, 'servergoods/goods/GoodsCategory/editGoodsCate', 'editGoodsCate', 'editGoodsCate');
    }

    /*
        根据id数组 启用/禁用一个或多个分类
        父类被禁用，则其所有子类也被禁用，开启同理
    */
    public function changeCateStatus(): array
    {
        $data = $this->receiveData(['id'=>0,'status'=>' ','token'=>' ']);
        return $this->stepRun($data,'servergoods/goods/GoodsCategory/changeCateStatus', 'changeCateStatus', 'changeCateStatus');
    }

    //删除一个或多个商品分类
    public function delCate(): array
    {
        $data = $this->receiveData(['id'=>[],'token'=>' ']);
        return $this->stepRun($data,'servergoods/goods/GoodsCategory/delCate', 'delCate', 'delCate');
    }

    //获取该父类的所有属性合集
    public function parentAllAttrs(): array
    {
        $data = $this->receiveData(['pid'=>0, 'token'=>' ']); 
        return $this->stepRun($data,'servergoods/goods/GoodsCategory/parentAllAttrs', 'parentAllAttrs', 'parentAllAttrs');
    }

    /*管理员推荐某个商品分类*/
    public function recommend(): array 
    {
        $data = $this->haveIssetReceiveData(['id'=>0, 'recommend'=>'','token'=>' ']);
        return $this->_addAppIdToRunOne($data, 'servergoods/goods/GoodsCategory/recommend', $this->goodsCategoryValidate, $this->goodsCategoryLogic, false, '');
    }


}
